package com.boang.obj;

import java.io.*;

/*
  @author: 13813
  @date: 2024/12/12 16:16
*/
public class ObjInputOutputDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        w();
        r();
    }

    private static void r() throws IOException, ClassNotFoundException {
        FileInputStream fileInputStream = new FileInputStream("fs.obj");
        ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        Student student = (Student) objectInputStream.readObject();
        System.out.println(student.name);
        System.out.println(student.age);
    }

    private static void w() throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream("fs.obj");
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);

        Student student = new Student("zhangsan", 20);

        objectOutputStream.writeObject(student);
    }
}
